﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace GMusicBox
{
    class Expander : ButtonX
    {
        public Expander()
        {
            this.DoubleBuffered = true;
        }

        internal bool expded = false, downned = false;//, moved = false, downned = false;
        public event EventHandler ExpandedChanged;

        public bool Expanded
        {
            get { return expded; }
            set
            {
                expded = value;
                if (ExpandedChanged != null) ExpandedChanged(this, new EventArgs());
                this.Invalidate();
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            downned = true;
            this.Invalidate();
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            downned = false;
            this.Invalidate();
            if (!expded)
            {
                expded = true;
                if (ExpandedChanged != null) ExpandedChanged(this, new EventArgs());
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            if (expded) g.DrawImage(res.bare5, 2, 3);
            else g.DrawImage(res.bare0, 2, 3);

            g.DrawString(this.Text, this.Font, Brushes.White, new PointF(19, 6));
            g.DrawString(this.Text, this.Font, Brushes.Black, new PointF(18, 5));
        }
    }
}
